package com.qf;

import com.qf.conf.LoadBalancerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
//启用eureka客户端
@EnableEurekaClient

//改变默认的负载均衡策略(name配置的服务的名称，configuration配置的是负载均衡策略的配置类)
@RibbonClient(name = "QF-ORDER",configuration = LoadBalancerConfig.class)
//开启Hystrix服务保护的支持
@EnableCircuitBreaker
//开启Feign客户端扫描(如果不指定具体扫描的包，扫当前主运行类所在包下的所有类)
@EnableFeignClients
public class QFUserApplication {

    public static void main(String[] args) {
        SpringApplication.run(QFUserApplication.class, args);
    }

    @Bean
    @LoadBalanced //将负载均衡器组件和当前的RestTemplate实现整合(内部整合的原理是依赖一个拦截器:LoadBalanceInteceptor)
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
